// miniprogram/pages/qlyx/lottery/lottery.js
Page({

  /**
   * 页面的初始数据
   */


  data: {
    scrollText: ['http://sd.offcn.com/zg/wximg/2021/hd/jlj/188.jpg', 'http://sd.offcn.com/zg/wximg/2021/hd/jlj/118.jpg', 'http://sd.offcn.com/zg/wximg/2021/hd/jlj/88.jpg', 'http://sd.offcn.com/zg/wximg/2021/hd/jlj/68.jpg', 'http://sd.offcn.com/zg/wximg/2021/hd/jlj/58.jpg', 'http://sd.offcn.com/zg/wximg/2021/hd/jlj/188.jpg', 'http://sd.offcn.com/zg/wximg/2021/hd/jlj/118.jpg', 'http://sd.offcn.com/zg/wximg/2021/hd/jlj/88.jpg', 'http://sd.offcn.com/zg/wximg/2021/hd/jlj/68.jpg', 'http://sd.offcn.com/zg/wximg/2021/hd/jlj/58.jpg',],
    animationData: null,
    num: 0
  },
  startScroll() {
    var that = this;

    console.log('开启')
    // 创建一个动画实例
    let animation = wx.createAnimation({
      duration: 6500,
      timingFunction: 'ease'
    })
    // 获取元素总高度
    let height = (this.data.scrollText.length - 1) * 218
    // 向上移动
    animation.translateY(-height + 'rpx').step()
    // 将动画效果赋值
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      that.lottery()
    }, 4000)



  },
  jpzs() {
    var that = this;
    that.setData({
      jpzs: 1
    })
  },
  close() {
    var that = this;
    that.setData({
      jpzs: !1,
      b: !1,
      a: !1,
      c: !1
    })
  },
  lottery() {
    var that = this;
    //获奖提示
    var phone = wx.getStorageSync('jlj2phone')
    var gonghao = wx.getStorageSync('gonghao')
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/choujiang/getcjusers?actid=42509&callback=?', //接收url
      data: {
        phone: phone,
        limits: 100
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson)
        if (theJson.status === 2) {
          wx.request({ //发送请求
            url: 'https://zg99.offcn.com/index/choujiang/lottery?actid=42509&callback=?', //接收url
            data: {
              phone: phone,
              gonghao: gonghao
            }, //接收参数
            success(res) {
              var jsonStr = res.data;
              jsonStr = jsonStr.replace("(", "");
              jsonStr = jsonStr.replace(")", "");
              if (typeof jsonStr != 'object') {
                jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                var theJson = JSON.parse(jsonStr);
              }
              console.log(theJson)
              wx.setStorageSync('prizename1', theJson.prizename)
              // _this.setData({
              //   jiang: true,
              //   isRunning: false
              // })
              wx.navigateTo({
                url: '../result/result',
              })

            }
          })

        } else if (theJson.status === 1) {
          wx.showModal({
            title: '您已经抽过奖了',
            content: '您获得了' + theJson.lists[0].prizename,
            showCancel: false, //去掉取消按钮
            success: function (res) {
             

              wx.navigateTo({
                url: '../list/list',
              })
            }
          })
        } else {
          wx.showModal({
            title: '次数不足',
            content: '您已经进行过抽奖了！',
            showCancel: false, //去掉取消按钮
            success: function (res) {
            
                wx.navigateTo({
                  url: '../list/list',
                })
              
              
            }
          })
        }
      }
    })


  },
  address() {
    var that = this;
    that.setData({
      a: !1,
      b: 1
    })
  },
  gowangk() {
    wx.navigateTo({
      url: '../ad/ad',
    })
  },
  tijiao() {
    var that = this;
    var phone = wx.getStorageSync('qlyxmobile')
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/choujiang/updateuser?actid=41651&callback=?', //接收url
      data: {
        phone: phone,
        name: that.data.name,
        mobile: that.data.mobile,
        address: that.data.address
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson)
        wx.showToast({
          title: '提交成功！',
        })
        wx.navigateTo({
          url: '../ad/ad',
        })
      }
    })
  },

  nameInput: function (e) {
    this.setData({
      name: e.detail.value
    })
    console.log(this.data.name)
  },
  mobileInput: function (e) {
    this.setData({
      mobile: e.detail.value
    })
    console.log(this.data.mobile)
  },
  addressInput: function (e) {
    this.setData({
      address: e.detail.value
    })
    console.log(this.data.addres)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var phone = wx.getStorageSync('qlyxmobile')
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/choujiang/getcjusers?actid=41651&callback=?', //接收url
      data: {
        phone: phone
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson)
        if (theJson.status == 1) {
          that.setData({
            fixed: 1,
            a: 1,
            prizename: theJson.lists[0].prizename
          })
        } else {
          that.setData({
            fixed: 1,
            c: 1,
          })
        }



      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */

  onShareAppMessage: function (res) {
    var that = this;
    if (res.from === 'button') {
      console.log(res.target)
    }
    var fx = wx.getStorageSync('fx')
    wx.setStorageSync('fx', fx + 1)
    if (fx == '1') {
      that.setData({
        num: 1
      })
    }
    return {
      title: "省考盲盒抽奖活动-中公教育抽奖活动",
      path: 'pages/qlyx/index/index',
      success: function (res) {
        console.log('成功', res)
      }
    }
  },

})